﻿using Newtonsoft.Json;
using System;
using System.IO;

namespace PhalApiClientSDK
{
    /**
    * JSON解析
    */
    public class PhalApiClientParserJson : PhalApiClientParser {

	    public PhalApiClientResponse parse(String apiResult) {
		    if (apiResult == null) {
                return new PhalApiClientResponse(408, null, "Request Timeout");
		    }
		
		    try {
                return JsonConvert.DeserializeObject<PhalApiClientResponse>(apiResult);
		    } catch (Exception ex) {
				File.AppendAllText("fail.log", "apiResult:" + apiResult + "\n\n" + ex.Message + "\n*****************************\n\n");
			    return new PhalApiClientResponse(500, null, "Internal Server Error: " + ex.Message);
		    }
	    }
    }
}
